package com.example.bootintegration.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

/**
 * @author Quintoy
 * @date 01/11/23
 */
@Aspect
@Component
public class LogAspect {



    @Pointcut("@annotation(Log)")
    public void logPointCut() {}

    @Around("logPointCut()")
    public void around(ProceedingJoinPoint joinPoint) {
        long start = System.currentTimeMillis();
        try {
            Log annotation = ((MethodSignature) joinPoint.getSignature()).getMethod().getAnnotation(Log.class);
            joinPoint.proceed();
        } catch (Throwable e) {
            e.printStackTrace();
        }
        long end = System.currentTimeMillis();
        System.out.println("execute time: " + (end - start));

    }
}
